import React, { Component } from 'react';
import { Form, Row, Col, Table } from 'antd';
import styles from '../../../index.less';
import * as commonFunc from '../../Common/commonFunc';

const FormItem = Form.Item;

class BindComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      // formData: props.formData,
      // workOrderJigSawData: props.workOrderJigSawData,
      // workOrderPrintData: props.workOrderPrintData,
      // hiddenProcess: props.hiddenProcess,
      dataList: [],
    };
  }

  componentWillMount() {

  }

  componentWillReceiveProps(nextProps) {
    const { workOrderJigSawData, workOrderPrintData, hiddenProcess } = nextProps;
    const printData = [...workOrderPrintData, ...hiddenProcess].filter(item => (item.handleType !== 'del'));
    const dataList = [];
    let key = 0;
    /* 遍历控制表获取每个部件对应工序 */
    for (const child of workOrderJigSawData) {
      let jigSawPrintData = [];
      if (child.sId !== undefined) {
        jigSawPrintData = printData.filter(item => (item.sControlId === child.sId || item.sType === '3'));
      } else {
        jigSawPrintData = printData.filter(item => (item.sControlId === child.key || item.sType === '3'));
      }
      /* 遍历每个部件对应工序进行排序 */
      const one = jigSawPrintData.filter(item => (item.sType === '0'));
      one.sort(commonFunc.iOrderSort);
      const oneShow = [];
      for (const v of one) {
        if (v.sProcessId !== undefined) {
          oneShow.push(v.sProcessId.split('[-]')[1]);
        }
      }
      const two = jigSawPrintData.filter(item => (item.sType === '1'));
      two.sort(commonFunc.iOrderSort);
      const twoShow = [];
      for (const v of two) {
        if (v.sProcessId !== undefined) {
          twoShow.push(v.sProcessId.split('[-]')[1]);
        }
      }
      const three = jigSawPrintData.filter(item => (item.sType === '2'));
      three.sort(commonFunc.iOrderSort);
      const threeShow = [];
      for (const v of three) {
        if (v.sProcessId !== undefined) {
          threeShow.push(v.sProcessId.split('[-]')[1]);
        }
      }
      const four = jigSawPrintData.filter(item => (item.sType === '3'));
      four.sort(commonFunc.iOrderSort);
      const fourShow = [];
      for (const v of four) {
        if (v.sProcessId !== undefined) {
          fourShow.push(v.sProcessId.split('[-]')[1]);
        }
      }
      let showInfo = '';
      if (oneShow.length > 0) {
        showInfo = `${oneShow.join('->')}`;
      }
      if (twoShow.length > 0) {
        if (showInfo !== '') {
          showInfo = `${showInfo}->${twoShow.join('->')}`;
        } else {
          showInfo = `${twoShow.join('->')}`;
        }
      }
      if (threeShow.length > 0) {
        if (showInfo !== '') {
          showInfo = `${showInfo}->${threeShow.join('->')}`;
        } else {
          showInfo = `${threeShow.join('->')}`;
        }
      }
      if (fourShow.length > 0) {
        if (showInfo !== '') {
          showInfo = `${showInfo}->${fourShow.join('->')}`;
        } else {
          showInfo = `${fourShow.join('->')}`;
        }
      }
      dataList.push({ sPartName: child.sPartsName, key, showInfo });
      key += 1;
    }
    // this.setState({
    //   workOrderJigSawData, workOrderPrintData, hiddenProcess, dataList,
    // });
  }

  render() {
    const columns = [{
      title: '部件名称',
      dataIndex: 'sPartName',
      key: 'sPartName',
    }, {
      title: '装订顺序',
      dataIndex: 'showInfo',
      key: 'showInfo',
    }];
    const { dataList } = this.state;
    return (
      <FormItem className={styles.workerForm}>
        <Row type="flex" className={styles.workerFormRow}>
          <Col span={1}>
            <div className={styles.item}>工<br />艺<br />流</div>
          </Col>
          <Col span={23}>
            <Table bordered columns={columns} dataSource={dataList} pagination={false} />
          </Col>
        </Row>
      </FormItem>
    );
  }
}

export default BindComponent;
